/*
* Copyright (c) 18/5/19 foo.com. All Rights Reserved.
*/
package com.cgmnx.admin.web.converter.vm;

import com.cgmnx.admin.dao.entity.ReplyEntity;
import com.cgmnx.admin.model.enums.ReplyAuditStatus;
import com.cgmnx.admin.web.converter.Convert;
import com.cgmnx.admin.web.model.vm.ReplyVm;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author: z Date: 18/5/19 Time: 下午7:51
 * @version: 1.0.0
 */
@Component
public class ReplyVmConverter implements Convert<ReplyEntity, ReplyVm> {

    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("");

    @Override
    public ReplyVm convert(ReplyEntity f) {

        ReplyVm t = new ReplyVm();

        t.setId(f.getId());
        t.setUserId(f.getUserId()) ;
        t.setReplyUserId(f.getReplyUserId());
        t.setUserName(f.getUserName());
        t.setNoteId(f.getNoteId()) ;
        t.setContent(t.getContent()) ;
        t.setTierNum(t.getTierNum());
        t.setLikeNum(t.getLikeNum()) ;
        final ReplyAuditStatus status = f.getStatus();
        if(status != null){
            t.setStatusCode(status.getCode()) ;
            t.setStatusName(status.getDesc());
        }
        t.setAuditTime(DATE_TIME_FORMATTER.format(LocalDateTime.ofInstant(f.getAuditTime().toInstant(), ZoneId.systemDefault())));
        t.setCreateTime(DATE_TIME_FORMATTER.format(LocalDateTime.ofInstant(f.getCreateTime().toInstant(), ZoneId.systemDefault())));
        t.setUpdateTime(DATE_TIME_FORMATTER.format(LocalDateTime.ofInstant(f.getUpdateTime().toInstant(), ZoneId.systemDefault())));
        t.setCreateUser(f.getCreateUser());
        t.setUpdateUser(f.getUpdateUser()) ;
        return t;
    }

    @Override
    public List<ReplyVm> convert(List<ReplyEntity> t) {
        return null;
    }
}
